﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Resources;
using System.Text;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using Puzzler.Plugin;
using Puzzler.Plugin.Interface;
using Puzzler.Plugin.Interface.Attributes;

namespace Puzzler.GUI.Converter
{
    public sealed class PuzzleInfoConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is PluginObject))
                throw new NotSupportedException();

            PluginObject plugin = value as PluginObject;
            PuzzleInfo puzzleInfo = plugin.PuzzleInfo;

            switch (parameter.ToString().ToLower())
            {
                case "name":
                    return puzzleInfo.Name;
                case "description":
                    return puzzleInfo.Description;
                case "note":
                    return puzzleInfo.Note;
                case "icon":
                    return BitmapFrame.Create(new Uri(puzzleInfo.IconUri));
                case "category":
                    return puzzleInfo.Category;
                default:
                    throw new NotSupportedException(parameter.ToString());
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
